from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-10 14:02:19.982698
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 10, Mar, 2022
Time: 14:02:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.4597
Nobs: 591.000 HQIC: -48.8670
Log likelihood: 7059.68 FPE: 4.61802e-22
AIC: -49.1269 Det(Omega_mle): 3.97075e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350192 0.067431 5.193 0.000
L1.Burgenland 0.108433 0.040937 2.649 0.008
L1.Kärnten -0.110596 0.021386 -5.171 0.000
L1.Niederösterreich 0.192373 0.085569 2.248 0.025
L1.Oberösterreich 0.123162 0.084433 1.459 0.145
L1.Salzburg 0.257923 0.043403 5.942 0.000
L1.Steiermark 0.035990 0.057263 0.629 0.530
L1.Tirol 0.101763 0.046273 2.199 0.028
L1.Vorarlberg -0.067885 0.040797 -1.664 0.096
L1.Wien 0.015972 0.075141 0.213 0.832
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051171 0.145059 0.353 0.724
L1.Burgenland -0.037874 0.088066 -0.430 0.667
L1.Kärnten 0.041861 0.046006 0.910 0.363
L1.Niederösterreich -0.203578 0.184078 -1.106 0.269
L1.Oberösterreich 0.458044 0.181634 2.522 0.012
L1.Salzburg 0.282606 0.093370 3.027 0.002
L1.Steiermark 0.113272 0.123186 0.920 0.358
L1.Tirol 0.304431 0.099543 3.058 0.002
L1.Vorarlberg 0.026374 0.087764 0.301 0.764
L1.Wien -0.027146 0.161646 -0.168 0.867
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198851 0.034411 5.779 0.000
L1.Burgenland 0.088867 0.020891 4.254 0.000
L1.Kärnten -0.007178 0.010914 -0.658 0.511
L1.Niederösterreich 0.240950 0.043667 5.518 0.000
L1.Oberösterreich 0.160165 0.043087 3.717 0.000
L1.Salzburg 0.040188 0.022149 1.814 0.070
L1.Steiermark 0.026570 0.029222 0.909 0.363
L1.Tirol 0.081572 0.023614 3.454 0.001
L1.Vorarlberg 0.054097 0.020819 2.598 0.009
L1.Wien 0.118104 0.038346 3.080 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119112 0.034410 3.462 0.001
L1.Burgenland 0.042649 0.020890 2.042 0.041
L1.Kärnten -0.013044 0.010913 -1.195 0.232
L1.Niederösterreich 0.171246 0.043665 3.922 0.000
L1.Oberösterreich 0.336803 0.043086 7.817 0.000
L1.Salzburg 0.099931 0.022149 4.512 0.000
L1.Steiermark 0.110805 0.029221 3.792 0.000
L1.Tirol 0.089574 0.023613 3.793 0.000
L1.Vorarlberg 0.060409 0.020819 2.902 0.004
L1.Wien -0.017750 0.038344 -0.463 0.643
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124318 0.064686 1.922 0.055
L1.Burgenland -0.044511 0.039271 -1.133 0.257
L1.Kärnten -0.045402 0.020515 -2.213 0.027
L1.Niederösterreich 0.135961 0.082085 1.656 0.098
L1.Oberösterreich 0.161648 0.080996 1.996 0.046
L1.Salzburg 0.284827 0.041636 6.841 0.000
L1.Steiermark 0.058340 0.054932 1.062 0.288
L1.Tirol 0.157368 0.044389 3.545 0.000
L1.Vorarlberg 0.097238 0.039136 2.485 0.013
L1.Wien 0.073423 0.072082 1.019 0.308
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077207 0.050502 1.529 0.126
L1.Burgenland 0.025768 0.030660 0.840 0.401
L1.Kärnten 0.053318 0.016017 3.329 0.001
L1.Niederösterreich 0.189905 0.064087 2.963 0.003
L1.Oberösterreich 0.331216 0.063236 5.238 0.000
L1.Salzburg 0.034985 0.032507 1.076 0.282
L1.Steiermark 0.008082 0.042887 0.188 0.851
L1.Tirol 0.118685 0.034656 3.425 0.001
L1.Vorarlberg 0.065862 0.030555 2.156 0.031
L1.Wien 0.097067 0.056277 1.725 0.085
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171583 0.060878 2.818 0.005
L1.Burgenland 0.004678 0.036959 0.127 0.899
L1.Kärnten -0.065994 0.019308 -3.418 0.001
L1.Niederösterreich -0.107405 0.077254 -1.390 0.164
L1.Oberösterreich 0.209545 0.076228 2.749 0.006
L1.Salzburg 0.054206 0.039186 1.383 0.167
L1.Steiermark 0.246733 0.051699 4.773 0.000
L1.Tirol 0.499808 0.041776 11.964 0.000
L1.Vorarlberg 0.064140 0.036833 1.741 0.082
L1.Wien -0.074114 0.067839 -1.092 0.275
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161277 0.067551 2.387 0.017
L1.Burgenland -0.002254 0.041010 -0.055 0.956
L1.Kärnten 0.062877 0.021424 2.935 0.003
L1.Niederösterreich 0.166085 0.085721 1.938 0.053
L1.Oberösterreich -0.055352 0.084583 -0.654 0.513
L1.Salzburg 0.208618 0.043480 4.798 0.000
L1.Steiermark 0.138156 0.057365 2.408 0.016
L1.Tirol 0.055712 0.046355 1.202 0.229
L1.Vorarlberg 0.146998 0.040870 3.597 0.000
L1.Wien 0.121110 0.075275 1.609 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390683 0.039717 9.837 0.000
L1.Burgenland -0.003343 0.024113 -0.139 0.890
L1.Kärnten -0.020906 0.012596 -1.660 0.097
L1.Niederösterreich 0.202313 0.050401 4.014 0.000
L1.Oberösterreich 0.228291 0.049732 4.590 0.000
L1.Salzburg 0.037061 0.025565 1.450 0.147
L1.Steiermark -0.015587 0.033728 -0.462 0.644
L1.Tirol 0.089796 0.027255 3.295 0.001
L1.Vorarlberg 0.050876 0.024030 2.117 0.034
L1.Wien 0.043707 0.044259 0.988 0.323
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036785 0.103463 0.167425 0.138153 0.096023 0.080217 0.032039 0.209274
Kärnten 0.036785 1.000000 -0.027443 0.131436 0.048326 0.084728 0.443585 -0.067159 0.089404
Niederösterreich 0.103463 -0.027443 1.000000 0.311039 0.118485 0.271264 0.065023 0.151586 0.289801
Oberösterreich 0.167425 0.131436 0.311039 1.000000 0.212095 0.294125 0.165974 0.135867 0.236439
Salzburg 0.138153 0.048326 0.118485 0.212095 1.000000 0.122189 0.090731 0.104627 0.123277
Steiermark 0.096023 0.084728 0.271264 0.294125 0.122189 1.000000 0.132588 0.105812 0.034851
Tirol 0.080217 0.443585 0.065023 0.165974 0.090731 0.132588 1.000000 0.063154 0.150192
Vorarlberg 0.032039 -0.067159 0.151586 0.135867 0.104627 0.105812 0.063154 1.000000 -0.005080
Wien 0.209274 0.089404 0.289801 0.236439 0.123277 0.034851 0.150192 -0.005080 1.000000